package com.zsrt.scott.servlet;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.zsrt.scott.service.impl.StudentServiceImpl;
import com.zsrt.scott.student.StudentEntity;

public class CxfServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	
	private StudentServiceImpl studentService;
	
	
	@Override
	public void init() throws ServletException {
		
		//此方法只执行1次 servlet是单例的 常驻内存
		
		WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		studentService = (StudentServiceImpl)context.getBean("studentService");
	}
	
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//1 获取业务逻辑类
		
		
		
		//2把数据添加到集合中
		StudentEntity student=new StudentEntity();
		request.getParameter("id");
		student.setId(Integer.parseInt(request.getParameter("id")));
		student.setAge(Integer.parseInt(request.getParameter("age")));
		student.setName(request.getParameter("name"));
		
		studentService.save(student);
	}
       

}
